package ro.ncit.tutorial01;

import android.app.ListActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class MainActivity extends ListActivity {

	private String[] valori;
	private MySimpleArrayAdapter adapter;
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		
		//apelati mereu super.onCreate()
		super.onCreate(savedInstanceState);
		
		/**
		 * Atentie! ListActivity easte o activitate speciala care nu are nevoie de setContentView.
		 * Aceasta incarca pe fundal un ListView automat, asa ca nu trebuie sa construiti explicit un layout.
		 */
		
		
		/**
		 *  TODO: Adaugati ce valori doriti in lista.
		 */
		valori = new String[] {"Android", "iOS"};
		
		/**
		 * Definim adaptorul pe care il vom folosi.
		 */
		MySimpleArrayAdapter adapter = new MySimpleArrayAdapter(this, R.layout.list_item, valori);
		
		/**
		 * Setam adaptorul.
		 */
		setListAdapter(adapter);
		
	}

	
	
	/**
	 * Ce se va intampla atunci cand doresti se apasa un element de pe lista.
	 */
	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		super.onListItemClick(l, v, position, id);
		
		//aici doar definim un Toast pentru a afisa ce element am selectat
		Toast.makeText(this, "Ati selectat: " + valori[position], Toast.LENGTH_SHORT).show();
		
		
	}
	
	
}
